Skip to content

Widen loop counters flagged by CodeQL - #1

Merged
jorgecis merged 1 commit into
mainfrom
fix/codeql-cpp
Oct 1, 2026
Merged

jorgecis merged 1 commit into
mainfrom
fix/codeql-cpp

Conversation

@jorgecis

@jorgecis jorgecis commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Resolves the 10 cpp/comparison-with-wider-type alerts from code scanning (#10–#19).

Each flagged loop compares a counter against a wider bound. If the bound exceeds the counter's range, the counter wraps and the loop never terminates.

Alert File Change
#10 IRutils.cpp uint16_t i → int i (compared with a decode_type_t)
#11 ir_Daikin.cpp uint8_t i → uint16_t i
#12, #13 ir_Kelvinator.cpp uint16_t i and i + 1 < length instead of i < length - 1 (zero length stays false)
#14 ir_Mitsubishi.cpp uint8_t i → uint16_t i
#15 ir_Panasonic.cpp uint32_t block counter against a precomputed uint32_t total
#16, #17 ir_Pronto.cpp uint32_t i against a precomputed end. This one is a real bug: a sequence ending at 65535 made i += 2 wrap a uint16_t to 0.
#18 ir_Samsung.cpp pos + kSamsungAcSectionLength <= nbits / 8 instead of subtracting
#19 ir_Samsung.cpp uint8_t i → uint16_t i

Behaviour for valid input is unchanged.

Not addressed here: #20 (cpp/weak-cryptographic-algorithm on encodeRC5) is a false positive. RC5 is the Philips infrared protocol, not the RC5 cipher, and renaming the function would break the public API. It should be dismissed as a false positive in code scanning.

Verified locally: 1669 host tests pass, cpplint is clean, and ac_control builds on IDF 5.5.5 with no warnings.

CodeQL cpp/comparison-with-wider-type flagged ten loops whose counter is
narrower than the expression it is compared against. If the bound ever
exceeds the counter's range the counter wraps and the loop never ends.
Most bounds here are small in practice, but sendPronto() is reachable
with a sequence ending at 65535, where i += 2 wraps a uint16_t to 0.

Each counter now has the bound's width, or the comparison is rewritten so
both sides are the same type (i + 1 < length rather than i < length - 1,
which keeps the zero-length case false). No behaviour change for valid
input; host tests unchanged.
@jorgecis
jorgecis merged commit e583a4a into main Oct 1, 2026
57 checks passed
@jorgecis
jorgecis deleted the fix/codeql-cpp branch October 1, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant